<cfmodule template="../../tag/layout.cfm" bodyIsEasyUILayout="false">
	<cfscript>
		if( structKeyExists(rc, "selectedids")  && len(trim(rc.selectedids))>0 )
		{
			selectedids = rc.selectedids;
		}else{
			selectedids = 0;
		}
	</cfscript>
	<fieldset>
		<legend>选择产品分类</legend>
		<input type="hidden" name="selectedids" id="selectedids" value="<cfoutput>#selectedids#</cfoutput>"/>
		<ul id="tt" class="easyui-tree" data-options="url:'?action=category.listtree&categorytypeid=100&selectedids=<cfoutput>#selectedids#</cfoutput>',checkbox:true"></ul></td>
	</fieldset>
</cfmodule>

<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}

	var submitForm = function($dialog, $categoryids ,$categorynames) {
		if(getChecked().length>0){
			$categoryids.val( getChecked() );
			$categorynames.val( getCheckedNames() );
			$dialog.dialog('destroy');
		}else{
			$.messager.alert('提示','请选择类别！','warning');
		}
	};

	$('#tt').tree({
		onExpand:function(node){
			checkChecked($('#selectedids').val());
		}
	});

	function getChecked(){
        var nodes = $('#tt').tree('getChecked');
        var ids = [];
        for(var i=0; i<nodes.length; i++){
        	ids.push(nodes[i].id);
        }
        return ids;
    }

    function getCheckedNames(){
        var nodes = $('#tt').tree('getChecked');
        var names = [];
        for(var i=0; i<nodes.length; i++){
        	names.push(nodes[i].text);
        }
        return names;
    }

    function checkChecked(ids){
		var selectedids = ids.split(',');
		for(var i=0;i<selectedids.length;i++){
			 var node = $('#tt').tree('find',selectedids[i]);
			 $('#tt').tree('check',node.target)
        }
	}

	$(function(){
		checkChecked( $('#selectedids').val() );
	})
</script>